package xiaolong.lian.service.impl;

import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import xiaolong.lian.dao.ArticleDao;
import xiaolong.lian.entity.Article;
import xiaolong.lian.service.ArticleService;

import java.util.List;

@Service
public class ArticleServiceImpl implements ArticleService {
    @Autowired
    private ArticleDao articleDao;

    /**
     * 注解方式的声明式事务
     * 代码里面多次dao层SQL操作将作为一个事务
     * 抛出RuntimeException才会自动回滚
     * @param keyword
     * @return
     */
    @Transactional
    public List<Article> getByTitleKeyword(String keyword) {
        LoggerFactory.getLogger(this.getClass()).debug("****** log *****");
        return articleDao.searchByTitle(keyword);
    }
}
